package cn.niit.pm.controller;

import cn.niit.pm.entity.Attendance;
import cn.niit.pm.entity.Contract;
import cn.niit.pm.service.impl.ContractServiceImpl;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 合同管理
 *
 * @author majiarui
 */
@Controller
@Api("合同管理")
public class ContractController {

    @Resource
    private ContractServiceImpl service;

    /**
     * 页面跳转
     *
     * @return
     */
    @GetMapping("/contract")
    public String contract(Contract attendance,
                           @RequestParam(value = "pageSize", defaultValue = "0") int pageSize,
                           @RequestParam(value = "pageNumber", defaultValue = "10") int pageNumber, Model model) {
        PageInfo info = service.select(attendance, pageSize, pageNumber);
        model.addAttribute("pageInfo", info);
        return "contract_infor/contract";
    }


    @PostMapping("/contract/insert")
    @ResponseBody
    public void insert(Contract contract) {
        service.insert(contract);
    }

    @PostMapping("/contract/update")
    @ResponseBody
    public void save(Contract contract) {
        service.update(contract);
    }

    @GetMapping("/contract/delete/{id}")
    @ResponseBody
    public void delete(@PathVariable("id") Integer id) {
        service.delete(id);
    }

    @GetMapping("/contract/selectById/{id}")
    @ResponseBody
    public Contract selectById(@PathVariable("id") Long id) {
        return service.selectById(id);
    }


}
